#include <iostream>
#include <vector>

#include <omp.h>

int main(int argc, char** argv)
{
    const int iDimension = 100;
    int i = 0;
    double start = 0.0;
    double stop = 0.0;
    double s = 0.0;

    std::cout<<"number of threads = " << omp_get_num_threads() << "\n";
    std::cout<<"number of devices = " << omp_get_num_devices() << "\n";
    std::cout<<"number of places  = " << omp_get_num_places() << "\n";
    std::cout<<"number of process = " << omp_get_num_procs() << "\n";
    std::cout<<"number of teams   = " << omp_get_num_teams() << "\n";
    omp_set_num_threads(20);
    std::cout<<"number of threads = " << omp_get_num_threads() << "\n";

    double *A = new double[iDimension];

    std::cout << "Initial value" << std::endl;
    start = clock();
#pragma omp parallel for
    for(i=0; i<iDimension; i++)
    {
        A[i] = double(i);
    }
    stop = clock();
    std::cout << "Time = " << (stop - start) / CLOCKS_PER_SEC << " s" << std::endl;

    std::cout << "Compute sum" << std::endl;
    s = 0.0;
    start = clock();
#pragma omp parallel for reduction(+:s)// schedule(static/dynamic/guided)
    for (i = 0; i < iDimension; i++) {
//#pragma omp critical(s)
        {
            s += A[i];
        }
    }
    stop = clock();
    std::cout << "Sum = " << s << std::endl;
    std::cout << "Time = " << (stop - start) / CLOCKS_PER_SEC << " s" << std::endl;

    delete[] A;

    return 0;
}
